package h0714;

import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 滑动窗口的最大值
 * @date 2024/7/14 14:19
 */
public class MaximumValueOfSlidingWindow {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //数字个数
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            int i1 = sc.nextInt();
            arr[i] = i1;
        }
        int m = sc.nextInt(); //窗口大小
        int max = getResult(arr, n, m);
        System.out.println(max);
    }

    private static int getResult(int[] arr, int n, int m) {
        int sum = 0;
        for (int i = 0; i < m; i++) {
            sum += arr[i]; //初始化sum
        }
        int max = sum;

        for (int i = 1; i <= n - m; i++) {
            sum += arr[i + m - 1] - arr[i - 1]; //滑动窗口本质上是减去第一个数字，加上紧接着的下一个数字。
            max = Math.max(sum, max);
        }
        return max;
    }
}
